cmake_minimum_required(VERSION 3.5)

# 设置工程名称;
set(PROJECT_NAME wannianCalendar)

# 用于设置版本;
string(TIMESTAMP  COMPILE_TIME_VERSION3 %y%m%d.%H%M)

# 编译时间;
string(TIMESTAMP  COMPILE_TIME_UTC UTC)

# 选择;
option(ENABLE_UNIT_TESTS "Enable unit tests" ON)
message(STATUS "Enable testing: ${ENABLE_UNIT_TESTS}")

# 设置工程版本号;
set(PRODUCT_MAJOR_VERSION  0 CACHE STRING "默认主要版本号")
set(PRODUCT_MINOR_VERSION  1 CACHE STRING "默认次级版本号")
set(PRODUCT_BUILD_NUMBER   ${COMPILE_TIME_VERSION3} CACHE STRING "默认构建号")

set(PRODUCT_BUILD_INCLUDE "${PROJECT_BINARY_DIR}/include")

# 拼写版本;
set(VERSION_PROJECT ${PRODUCT_MAJOR_VERSION}.${PRODUCT_MINOR_VERSION}.${PRODUCT_BUILD_NUMBER})
message(STATUS "App Version:"${VERSION_PROJECT})
# 编译时间;
set(BUILD_TIME  ${COMPILE_TIME_UTC})

# 工程定义;
project(${PROJECT_NAME}
    LANGUAGES CXX
    VERSION ${VERSION_PROJECT}
)
# 设置库名称;
set(PROJECT_LIB lib${PROJECT_NAME})
# 设置C++ 版本;
# 将 C++ 标准设置为使用自动的合适标准;
# target_compile_features(${PROJECT_NAME} PUBLIC cxx_auto_type)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)


if(CMAKE_COMPILER_IS_GNUCXX)
    add_compile_options(-fPIC)
elseif(MSVC)
    ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
    add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
    add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
endif()


include(cmake/Utility.cmake)

# 获取当前分支;
set(GIT_BRANCH_NAME "Unkown")
get_git_app_branch(GIT_BRANCH_NAME)

# 获取当前的git hash;
set(GIT_COMMIT_HASH "Unkown")
get_git_app_hash(GIT_COMMIT_HASH)

# 获取当前的 app 版本;
set(GIT_APP_VERSION "Unkown")
get_git_app_version(GIT_APP_VERSION)

configure_file("${PROJECT_SOURCE_DIR}/Config/Config.hpp.in"  "${PRODUCT_BUILD_INCLUDE}/Config/Config.hpp")
add_compile_options(-I${PRODUCT_BUILD_INCLUDE})
# set(CMAKE_BUILD_TYPE "Debug")
# 打印此版本的 CMake 的已知编译特性列表
#message("List of compile features: ${CMAKE_CXX_COMPILE_FEATURES}")

#设置二进制文件输出路径;
#set(CMAKE_BUILD_RPATH ${PROJECT_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)


# 头文件;
include_directories(include)

# 源文件;
file(GLOB_RECURSE SOURCE "src/*")
# list(REMOVE_ITEM  SOURCE "${PROJECT_SOURCE_DIR}/src/main.cpp")

# message(STATUS ${SOURCE})

# 库;
add_library(${PROJECT_LIB} STATIC ${SOURCE})
# 生成执行程序;
add_executable(${PROJECT_NAME} "main.cpp")
# 链接库；
target_link_libraries(${PROJECT_NAME} ${PROJECT_LIB})
# 添加测试代码单元目录;
if(ENABLE_UNIT_TESTS)
    if (EXISTS  "${CMAKE_CURRENT_SOURCE_DIR}/UnitTest" )
        add_subdirectory(UnitTest)
    endif()
endif()